open(BUFF,"../merge_IBC/mapping.txt") or die "no file found ../merge_IBC/mapping.txt\n";
while(<BUFF>)
{
	chomp($_);
	$_=~s/ /\t/g;
	@array=split("\t",$_);
	#print "@array\n";
	#$hash{$array[1]}=@array[@array-1];
	$hash{$array[@array-1]}=$array[1];
	#print "$array[@array-1]\t$array[1]\n";
}
close(BUFF);
open(FAM,"merge_final.fam") or die "no file found merge_final.fam\n";
open(WRFAM,">extract_merge_final1.fam") or die "not able to extract merge_final.fam\n";
open(WRREPLACE,">replace_merge_final.fam") or die "not able to extract merge_final.fam\n";
$in=0;
$out=0;
while(<FAM>)
{
	chomp($_);
	@fam=split(" ",$_);
	if(exists($hash{$fam[1]}))
	{
		#$in++;
		print WRFAM $_."\n";	
		$fam[0] = $hash{$fam[1]};
		$fam[1] = $hash{$fam[1]};
		$_ = join(" ",@fam);
		print WRREPLACE $_."\n";
	}
	else
	{
		#$out++;
	}
}
close(FAM);
close(WRFAM);
close(WRREPLACE);
#print "$in $out\n";
